/**
 * @author  Thomas Lehmann
 * @file    StringToolsTest.js
 * @note    //http://docs.busterjs.org/en/latest/modules/buster-assertions/
 *
 * Copyright (c) 2013 Thomas Lehmann
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
var buster            = require("buster");
var StringToolsModule = require("../src/StringTools.js");
var StringTools       = StringToolsModule.StringTools;

/**
    Testing class (function) "StringTools".
 */
buster.testCase("Testing class StringTools:", {
    /**
        Testing of StringTools.isBracket(character) method.
     */
    "testing 'StringTools.isBracket(...)'": function() {
        var tools = new StringTools();
        assert.equals(true, tools.isBracket("["));
        assert.equals(true, tools.isBracket("]"));

        assert.equals(true, tools.isBracket("{"));
        assert.equals(true, tools.isBracket("}"));

        assert.equals(true, tools.isBracket("("));
        assert.equals(true, tools.isBracket(")"));

        var characters  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        characters     += "0123456789";
        characters     += "!?=$%&/\\=+-*#'\";,:.<>|~^`"

        for (index = 0; index < characters.length; ++index) {
            assert.equals(false, tools.isBracket(characters[index]));
        }
    },

    /**
        Testing of StringTools.isSpecialCharacter(character) method.
     */
    "testing 'StringTools.isSpecialCharacter(...)'": function() {
        var tools = new StringTools();
        var specialCharacters = "#?=%&/+-*;,:.<>|~^";

        for (index = 0; index < specialCharacters.length; ++index) {
            assert.equals(true, tools.isSpecialCharacter(specialCharacters[index]));
        }

        var characters  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        characters     += "0123456789";

        for (index = 0; index < characters.length; ++index) {
            assert.equals(false, tools.isSpecialCharacter(characters[index]));
        }
    },

    /**
        Testing of StringTools.isAlpha(character) method.
     */
    "testing 'StringTools.isAlpha(...)'": function() {
        var tools = new StringTools();
        var characters  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

        for (index = 0; index < characters.length; ++index) {
            assert.equals(true, tools.isAlpha(characters[index]));
        }

        characters  = "0123456789";
        characters += "!?=$%&/\\=+-*#'\";,:.<>|~^`"

        for (index = 0; index < characters.length; ++index) {
            assert.equals(false, tools.isAlpha(characters[index]));
        }
    },

    "testing 'StringTools.startsWith(...)'": function() {
        var tools = new StringTools();

        var text1 = "this is a small test";
        assert.equals(true , tools.startsWith(text1, 0, "this"),
                      "text does not start with 'this'");
        assert.equals(false, tools.startsWith(text1, 0, "thiss"),
                      "text should not start with 'thiss'");

        var text2 = "hello";
        assert.equals(false, tools.startsWith(text2, 0, "hello world"));
    }
});

